const validate = require("@/utils/validate");
const { body, query } = require("express-validator");

const register = validate([
  body("username")
    .notEmpty()
    .trim()
    .withMessage("请输入账号")
    .isAlpha()
    .withMessage("账号由大小写字母组成")
    .isLength({ min: 4, max: 10 })
    .withMessage("账号长度4-10个字符"),
  body("password")
    .notEmpty()
    .isAlphanumeric()
    .isLength({ min: 6, max: 12 })
    .withMessage("密码由6-12个大小写字母和数字组成"),
  body("email")
    .notEmpty()
    .withMessage("请输入邮箱")
    .isEmail()
    .withMessage("邮箱格式不正确"),
]);

const login = validate([
  query("username")
    .notEmpty()
    .trim()
    .withMessage("请输入账号")
    .isAlpha()
    .withMessage("账号由大小写字母组成")
    .isLength({ min: 4, max: 10 })
    .withMessage("账号长度4-10个字符"),
  query("password")
    .notEmpty()
    .withMessage("请输入密码")
    .isAlphanumeric()
    .withMessage("密码由大小写字母和数字组成")
    .isLength({ min: 6, max: 12 })
    .withMessage("密码长度为6-12字符"),
  query("key").notEmpty().withMessage("key缺少"),
  query("code").notEmpty().withMessage("请输入验证码"),
]);

module.exports = { register, login };
